<?php 
include('common_include.php');
include('validateSession.php');

$operation = $_POST["operation"];
$statusCriteria = $_POST["statusCriteria"];

$ordersHeaderArr = array();
$dao = new SQLitePersistence();
if ($operation == 'Search') {
	if ($statusCriteria != '') {
		$ordersHeaderArr = $dao->getOrdersHeaderByStatus($statusCriteria);
	}
} else {
	$ordersHeaderArr = $dao->getAllOrdersHeader();
}
//print_r($ordersHeaderArr);
unset($dao);
?>

<html>
<head>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<script language="javascript" src="scripts/common.js"></script>
<title>
	Update Order Settlements
</title>
<script>
var popupWidth = 800;
var popupHeight = 500;
var posTopLeftX = (screen.width/2) - (popupWidth/2);
var posTopLeftY = (screen.height/2) - (popupHeight/2);

function showOrderDetails(orderID) {
	var popupSpec = "menubar=0,resizable=0,width="+popupWidth+",height="+popupHeight+",left="+posTopLeftX+",top="+posTopLeftY;
	window.open("order_update_details.php?orderID=" + orderID,"SettlementDetail",popupSpec);
}

function filterBy() {
	document.forms[0].operation.value = 'Search';
	document.forms[0].submit();
}
</script>

<body>
<form action="order_update.php" method="post">
<table>
	<tr>
		<td class="errorLabel">
			<?php echo $_GET['error']; ?>
		</td>
	</tr>
	<tr>
		<td class="labelClass">
			Order Settlements Search Filter:
		</td>
	</tr>
	<tr>
		<td class="labelClass">
			<input type="hidden" name="operation" value="NoOperation"/>
			<select id="statusCriteriaSelect" name="statusCriteria">
				<option value="NEW">NEW</option>
				<option value="PAID">PAID</option>
			</select>
			&nbsp;&nbsp;&nbsp;
			<input type="button" value="Search" onclick="filterBy();"/>
		</td>
	</tr>		
	<tr>
		<td class="labelClass">
			Order Settlements Listing:
		</td>
	</tr>
	<tr>
		<td class="labelClass">
			<table class="listingTable"> 
				<tr class="yellow">
					<td class="adjacent">
						Customer Name
					</td>
					<td class="adjacent">
						Customer Contact
					</td>
					<td class="adjacent">
						Customer Email
					</td>
					<td class="adjacent">
						Delivery Mode
					</td>										
					<td class="adjacent">
						Payment Mode
					</td>					
					<td class="adjacent">
						Total Amount
					</td>										
					<td class="adjacent">
						Status
					</td>					
					<td class="adjacent">
						Order Date
					</td>														
					<td class="adjacent">
						&nbsp;
					</td>
				</tr>
				<?php for ($i=0; $i < sizeof($ordersHeaderArr); $i++) {
					//$rowIDAttr = 'sequence_' . $i;
					//$hiddenInitSeq = 'initSeq_' . $i;
					$aOrderHeader = $ordersHeaderArr[$i];
					$popupForOrderDetails = 'showOrderDetails(' . $aOrderHeader->getOrderId() . ');';
					/*$outletIDHidden = 'outlet[' . $i . '][outletID]';
					$outletLocation = 'outlet[' . $i . '][location]';
					$outletAddress = 'outlet[' . $i . '][address]';
					$outletTelephone = 'outlet[' . $i . '][telephone]';
					$outletSeq = 'outlet[' . $i . '][outletSeq]';*/
				?>
				<tr class="yellow">
					<td class="adjacent">
						<?php echo $aOrderHeader->getCustName();?>
					</td>
					<td class="adjacent">
						<?php echo $aOrderHeader->getCustContact();?>
					</td>
					<td class="adjacent">
						<?php echo $aOrderHeader->getCustEmail();?>
					</td>
					<td class="adjacent">
						<?php echo $aOrderHeader->getDeliveryMode();?>
					</td>										
					<td class="adjacent">
						<?php echo $aOrderHeader->getPaymentMode();?>
					</td>					
					<td class="adjacent">
						<?php echo $aOrderHeader->getTotalAmt();?>
					</td>										
					<td class="adjacent">
						<?php echo $aOrderHeader->getStatus();?>
					</td>					
					<td class="adjacent">
						<?php echo $aOrderHeader->getOrderDt();?>
					</td>														
					<td class="adjacent">
						<input type="button" value="Show Details" onclick="<?php echo $popupForOrderDetails?>"/>
					</td>
				</tr>
				<?php } 
				unset($outletArr);?>				
			</table>
		</td>
	</tr>
</table>
</form>
</body>
</html>

